const redis=require('../models/redis.server.model');
const map={
    getTopics:'获取话题列表',
    getTopic:'获取话题详情',
    getUser:'获取用户信息',
    getTagList:'获取标签列表',
    getTagTopics:'获取标签话题列表',
    getArchiveList:'获取归档列表',
    getArchiveTopics:'获取归档话题'
};

module.exports=opts=>async (ctx,next)=>{
    let ret=await redis.getLimit({action:opts.action,id:ctx.request.ip});
    console.log(`Api ip limit [${map[opts.action]}] ret:`,ret);
    if(ret)return ctx.body={code:400,msg:map[opts.action]+'频繁，请稍候再试'};
    await next();
};